package user

import (
	login "AI/Services/Login"
	route "AI/router"
	"database/sql"
	"encoding/json"
	"net/http"

	"github.com/gin-gonic/gin"
	_ "github.com/go-sql-driver/mysql"
)

var db *sql.DB

func init() {
	route.Register(&User{})

}

type User struct {
}
type Login struct {
	Account string
	pws     string
}

func (api *User) Pages_get(c *gin.Context) { //,httpMethod string
	//api.httpMethod="GET"
	// users := []int{1,2,3}
	status, _ := c.Get("status")
	if status == 401 {
		c.JSON(http.StatusOK, gin.H{
			"code": status,
			"msg":  "ok",
			"data": "未登录",
		})
		return
	}
	c.JSON(http.StatusOK, gin.H{
		"code":     1,
		"msg":      "ok",
		"data":     "成功",
		"username": "123",
	})

}

func (api *User) AddUser(c *gin.Context) { //,httpMethod string
	//api.httpMethod="GET"
	users := []int{2, 3, 6}
	c.JSON(http.StatusOK, gin.H{
		"code": 1,
		"msg":  "ok",
		"data": users,
	})

}

func (api *User) Login(c *gin.Context) { //,httpMethod string
	Data := make(map[string]string)
	json.NewDecoder(c.Request.Body).Decode(&Data)
	login.PasOrAccount(Data, c)
}
